import { _decorator, Component, Node, Label } from 'cc';
import { SingleKeyListener } from './input/GameInputListeners';
import GameInputMgr from './input/GameInputMgr';
import GameInputOperator from './input/GameInputOperator';
import { config, KeyCodeMatch } from './input/InputConfig';
import InputConverter from './input/InputConverter';
const { ccclass, property } = _decorator;

@ccclass('NewTest')
export class NewTest extends Component implements SingleKeyListener {


    @property(Label)
    labelRocker: Label = null;

    @property(Label)
    labelButton: Label = null;

    onKeyBoardPress(keyCode: number): void {
        this.labelRocker.string = "" + keyCode;
        let name = GameInputMgr.getInstance().converter.getKeyName(keyCode);
        this.labelButton.string = name;
    }


    onKeyBoardRelease(keyCode: number): void {

    }


    isBlockInput(): boolean {
        return false;
    }


    onRockerEvent(index: number, x: number, y: number): void {
        this.labelRocker.string = index + " x " + Math.floor(x) + " y " + Math.floor(y);
    }



    start() {
        // InputConverter.getInstance().init(KeyCodeMatch)
        GameInputMgr.getInstance().converter.init(KeyCodeMatch)
        GameInputOperator.getInstance().init(config, KeyCodeMatch)
        GameInputOperator.getInstance().on('NewTest', this)
        GameInputMgr.getInstance().addKeyListener(this)
    }

    update(deltaTime: number) {

    }

    onDestroy() {
        GameInputOperator.getInstance().off('NewTest')
        GameInputMgr.getInstance().removeKeyListener(this)
    }

    onButtonClick() {
        console.log('NewTest  onButtonClick ')
    }

    onButtonClick2() {
        console.log('NewTest  onButtonClick 2')
    }

    onButtonClick3() {
        console.log('NewTest  onButtonClick 3')
    }
}

